import yaml
from Const import *
import os


def record_pictures(pictures, filepath=YAMLPATH):
    # temp = []
    # for pic in pictures:
    #     temp.append(pic.get_it_gens())
    try:
        with open(filepath, "w") as f:
            yaml.dump(pictures, f)
    except FileNotFoundError:
        os.mkdir(os.path.join(BASEPATH, "result"))


def record_gens(gens, filepath=YAMLPATH):
    # temp = []
    # for pic in pictures:
    #     temp.append(pic.get_it_gens())
    with open(filepath, "w") as f:
        yaml.dump(gens, f)


def read_gens(filepath=YAMLPATH):
    with open(filepath, "r")as f:
        gens = yaml.load(f)
    return gens


def read_pictures(filepath=YAMLPATH):
    with open(filepath, "r") as f:
        pictures = yaml.load(f)
    return pictures


if __name__ == '__main__':
    temp = read_pictures()
    for pic in temp:
        print(pic.get_it_fitness())
